﻿<Page 
    x:Class="Milkify.Views.TaskListControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:m="clr-namespace:Milkify"
    xmlns:md="clr-namespace:Milkify.Data"
    xmlns:mcm="clr-namespace:Milkify.ComponentModel"
    Title="List"
    KeepAlive="True"
    Name="PageTasks">
    <Page.Resources>
        <ObjectDataProvider
            ObjectType="{x:Type sys:Enum}"
            MethodName="GetValues"
            x:Key="TaskListFilterValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="md:TaskListFilter" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <ObjectDataProvider
            ObjectType="{x:Type sys:Enum}"
            MethodName="GetValues"
            x:Key="TaskListSortValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="md:TaskListSort" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <mcm:BooleanToVisibilityConverter 
            x:Key="TaskFunctionButtonsVisibilityConverter" 
            FalseVisibility="Collapsed" />
    </Page.Resources>
    <DockPanel>
        <Grid
            KeyboardNavigation.TabIndex="1"
            DockPanel.Dock="Bottom"
            Style="{DynamicResource TaskListSortAndFilterPanelStyle}">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock
                Grid.Column="0">
                <Run Text="Sort tasks (" />
                <Hyperlink NavigateUri="#" RequestNavigate="HyperlinkAscOrDesc_RequestNavigate"><TextBlock x:Name="TextAscOrDesc" Text="ascending" /></Hyperlink>
                <Run Text=")" />
            </TextBlock>
            <ComboBox
                Grid.Column="0"
                Grid.Row="1"
                Name="ComboSort"
                KeyboardNavigation.TabIndex="1"
                ItemsSource="{Binding Source={StaticResource TaskListSortValues}}"
                SelectedValue="{x:Static md:TaskListSort.Priority}"
                SelectionChanged="ComboSort_SelectionChanged"
                Style="{DynamicResource TaskListSortComboStyle}" />
            <TextBlock
                Grid.Column="1"
                Text="Filter tasks" />
            <ComboBox
                Grid.Column="1"
                Grid.Row="1"
                Name="ComboFilter"
                KeyboardNavigation.TabIndex="2"
                ItemsSource="{Binding Source={StaticResource TaskListFilterValues}}"
                SelectedValue="{x:Static md:TaskListFilter.Incomplete}"
                SelectionChanged="ComboFilter_SelectionChanged"
                Style="{DynamicResource TaskListFilterComboStyle}"/>
        </Grid>
        <Grid
            KeyboardNavigation.TabIndex="2"
            DockPanel.Dock="Bottom"
            Style="{DynamicResource TaskListFunctionsPanelStyle}">
            <Grid.RowDefinitions>
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Button
                Grid.Column="0"
                Content="Complete"
                Visibility="{Binding SelectedTasksAreIncomplete, ElementName=PageTasks, Converter={StaticResource TaskFunctionButtonsVisibilityConverter}}"
                Command="{Binding CompleteTasksCommand}" />
            <Button
                Grid.Column="1"
                Content="Edit"
                Visibility="{Binding SelectedTasksAreIncomplete, ElementName=PageTasks, Converter={StaticResource TaskFunctionButtonsVisibilityConverter}}"
                Command="{Binding EditTasksCommand}" />
            <Button
                Grid.Column="2"
                Content="Postpone"
                Visibility="{Binding SelectedTasksAreIncomplete, ElementName=PageTasks, Converter={StaticResource TaskFunctionButtonsVisibilityConverter}}"
                Command="{Binding PostponeTasksCommand}" />
            <Button
                Grid.Column="3"
                Content="Delete"
                Visibility="{Binding SelectedTasksAreIncomplete, ElementName=PageTasks, Converter={StaticResource TaskFunctionButtonsVisibilityConverter}}"
                Command="{Binding DeleteTasksCommand}" />
            <Button
                Grid.Column="4"
                Content="Uncomplete"
                Visibility="{Binding SelectedTasksAreCompleted, ElementName=PageTasks, Converter={StaticResource TaskFunctionButtonsVisibilityConverter}}"
                Command="{Binding UncompleteTasksCommand}" />
        </Grid>
        <ListBox
            Name="ListTasks"
            ItemsSource="{Binding Tasks}"
            SelectionMode="Multiple"
            KeyboardNavigation.TabIndex="0"
            KeyboardNavigation.IsTabStop="False"
            KeyboardNavigation.DirectionalNavigation="Cycle"
            KeyboardNavigation.TabNavigation="Once"
            Grid.IsSharedSizeScope="True"
            Style="{DynamicResource TaskListStyle}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Button
                        Name="ButtonTask"
                        Content="{Binding}"
                        ContentTemplate="{StaticResource TaskItem}"
                        Command="{Binding ElementName=ListTasks, Path=DataContext.NavigateToTaskCommand}"
                        CommandParameter="{Binding}"
                        Style="{DynamicResource TaskButtonStyle}"
                        Click="ButtonTask_Click" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </DockPanel>
</Page>
